-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PR: Fix folding and make some performance improvements (Editor) #21669
Conversation
Hello @ccordoba12! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:
Comment last updated at 2024-02-07 18:19:43 UTC |
91360f4
to
beb2c1a
Compare
d9e7c03
to
10ebc32
Compare
10ebc32
to
ba770b3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for keeping the commit history so clean. It meant that I could fairly easily steps through the commit instead of viewing all the hundreds of lines at once.
I have only a couple of minor comments, some general, some specific to the code. I'm happy for you to merge after you have had a look at what I wrote.
-
Pressing
Tab
on a folded line indents the whole folded region (this is fine), but it also selects the folded region (this is a bit weird). PressingShift
+Tab
un-indents only the first line of the folded region. I don't think this is intentional. It's a bit of a boundary case, though, so not that important. -
The folding indicator no longer changes colour when you hover above them. That's not a problem as far as I am concerned.
-
Remove folded regions when pressing Delete or Backspace in a folded line. I took this idea from VSCode.
This means that the editor acts as if the whole folded region is selected if you are on a folded line. The user can't edit a folded line (unless they unfold), they can only delete the whole folded region. I find that surprising, which is not good. On the other hand, I never use folding so I don't have an intuition, and if VSCode does this then the UX is probably not too bad. Thus I'm fine with this.
-
Preserve syntax highlighting for folded lines and extend their background color to the full width of the editor
The disadvantage is that before it was obvious when a region was folded, but now it is less so. I guess the chevron should be enough of a sign for users.
This prevents freezes in the interface, which was happening before because half of that computation was done on the main thread.
…esponses This fixes showing LSP errors on our side, which was broken before (who knows since when).
This prevents freezing the interface by running that computation on the main thread.
Now we use a timer to avoid too many calls to that method.
… there is an active snippet
This allows to perform that task on the thread we have for folding, instead of doing it on the main one.
Also, remove some unused attributes
This was totally broken.
- We need to do this because those operations could have removed some block decorations. - This also allows us to call the _on_key_pressed and _expand_selection methods only when they are needed.
This clears some decorations that are left in the editor when undoing the removal of unfolded regions.
- This gives more flexibility regarding when to paint those regions. - It also prevents some glitches in the interface when undoing the removal of folded regions.
This prevents not painting folded decorations on lines close to the visible region.
Also, highlight folded blocks when updating decorations in the editor. This is necessary to decorate blocks not detected as folded by merge_folding, which are outside of the editor's buffer region.
We're not using them, so that code is not really necessary.
This also fixes the problem that uncollapsed icons were barely visible on the light theme when hovering the folding panel because they had a yellow color.
They are the same ones used by VSCode and easier to tell apart.
- Correctly paint the panel on hover for the light theme. - Remove foreground color and outline for folded blocks and paint their decorations in full width instead.
Also, use qdebounce instead of a timer to simplify code a bit.
This way we avoid to compute one extra `for` loop while updating folding.
Also, remove an unnecessary block comment.
That avoids an extra operating to get a reference for it in several places.
dc4fea8
to
5879b6d
Compare
304a694
to
8004add
Compare
Thanks for the review @jitseniesen! About your comments:
I was not aware of that and it was not intended. So, I made that pressing Tab and Shift+Tab in a folded line do nothing.
The problem is that if we allow editing folded lines, the editor could be left in an inconsistent state in the sense that the new results coming from the LSP could not include the current line as folded. That's why folded lines are like read-only ones.
Ok, thanks for the remark.
A point in favor of that change is that folded lines are now highlighted to the editor's full width. So you can spot them while moving up and down more easily. And this is also what VSCode does, i.e. it preserves syntax highlighting in folded lines. |
I mean, if I move the cursor to a folded line and then I press for instance |
Also, make others run on Windows
Co-authored-by: Jitse Niesen <[email protected]>
Ok, that's a good point and I also agree with it, so I'll implement it before merging this PR. |
8004add
to
2fdd883
Compare
That will make appear as read-only to users.
2fdd883
to
ed35459
Compare
I think this one is finally ready. @jitseniesen, if you find additional issues with folding please open a new issue and I'll address them in a follow-up PR. |
Description of Changes
For folding
Delete
orBackspace
in a folded line. I took this idea from VSCode.Other improvements
Visual changes
Use chevron icons in the folding panel and move it to be next to the code
The last part preserves the UI we have in Spyder 5, which I think is the right one.
Preserve syntax highlighting for folded lines and extend their background color to the full width of the editor
I took this idea from VSCode.
Fix style of the folding panel in the light theme
Issue(s) Resolved
Part of #21637.
Affirmation
By submitting this Pull Request or typing my (user)name below,
I affirm the Developer Certificate of Origin
with respect to all commits and content included in this PR,
and understand I am releasing the same under Spyder's MIT (Expat) license.
I certify the above statement is true and correct: @ccordoba12